﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaiDouCommon.Model;

namespace TaiDouPhotonServer.DB.Manager
{
    //角色管理类
    public class RoleManager
    {
        /// <summary>
        /// 根据用户获取所有角色列表
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public List<Role> GetRoleListByUser(User user) {
            using (var session = NHiberateHelper.OpenSession()) {
                using (var transation = session.BeginTransaction()) {
                    var list = session.QueryOver<Role>().Where(role =>role.user == user);
                    transation.Commit();
                    return (List<Role>)list.List();
                }
            }

        }

        //添加角色
        public void AddRole(Role role)
        {
            using (var session = NHiberateHelper.OpenSession())
            {
                using (var transation = session.BeginTransaction())
                {
                    session.Save(role);
                    transation.Commit();
                }
            }
        }
    }
}
